h[100000],o[100000];long a,t;main(i,n,v,j,l){for(;scanf("%d%d",&n,h)-1;printf("%ld\n",a)){for(*o=i=1,a=0,l=0;i++<n;){scanf("%d",&v);if(h[l]<v)h[++l]=v,o[l]=i;else if(h[l]>v){while(~l&&h[l]>v)t=1L*h[l]*(i-o[l]),a=a>t?a:t,l--;h[++l]=v;}}for(j=0;j<=l;t=1L*h[j]*(n-o[j++]+1),a=a>t?a:t);}}
